package world.hezi.pojo;

import world.hezi.Buildable;
import world.hezi.AbstractBuilder;

import java.util.Optional;

public class AICommand implements Buildable<AICommand> {
    private String p;
    private String n;
    private Integer w;
    private Integer h;
    private Boolean i;
    public AICommand(){}
    public AICommand(String p, String n, Integer w, Integer h, Boolean i) {
        this.p = p;
        this.n = n;
        this.w = w;
        this.h = h;
        this.i = i;
    }

    public AICommand(String p, String n, Integer w, Integer h) {
        this.p = p;
        this.n = n;
        this.w = w;
        this.h = h;
        this.i = false;
    }

    public String getP() {
        return p;
    }

    public String getN() {
        return n;
    }

    public Integer getW() {
        return w;
    }

    public Integer getH() {
        return h;
    }

    public Boolean getI() {
        return i;
    }

    @Override
    public AbstractBuilder<AICommand> builder(){
        return new Builder();
    }
    static class Builder implements AbstractBuilder<AICommand> {
        private String p;
        private String n;
        private Integer w;
        private Integer h;
        private Boolean i;

        public Builder setP(String p) {
            this.p = p;
            return this;
        }

        public Builder setN(String n) {
            this.n = n;
            return this;
        }

        public Builder setW(Integer w) {
            this.w = w;
            return this;
        }

        public Builder setH(Integer h) {
            this.h = h;
            return this;
        }

        public Builder setI(Boolean i) {
            this.i = i;
            return this;
        }
        @Override
        public AICommand build(){
            return new AICommand(
                    p==null?"":p,
                    n==null?"":n,
                    w==null?512:w,
                    h==null?512:h,
                    i != null && i);
        }
        @Override
        public Builder setField(String fieldName, Object value) {
            if (fieldName==null||value==null){
                return this;
            }
            return this
                    .setH("h".equals(fieldName)? Integer.parseInt(String.valueOf(value)) : Optional.ofNullable(this.h).orElse(512))
                    .setP("p".equals(fieldName)? String.valueOf(value) :this.p)
                    .setI("i".equals(fieldName))
                    .setN("n".equals(fieldName)? String.valueOf(value) :this.n)
                    .setW("w".equals(fieldName)? Integer.parseInt(String.valueOf(value)) :Optional.ofNullable(this.w).orElse(512));
        }
    }

}
